package com.xczl.book.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.xczl.book.dao.BookCateDao;
import com.xczl.book.entity.BookCate;

@Service
@Transactional
public class BookCateService {

	@Autowired
	private BookCateDao bookCateDao;
	
	/**
	 * 添加
	 * @param bookCate
	 */
	public void add(BookCate bookCate){
		//实体是否存在
		Assert.notNull(bookCate);
		Assert.hasText(bookCate.getName());
		//Dao插入数据
		bookCateDao.insertBookCate(bookCate);
	}
	
	/**
	 * 修改
	 * @param bookCate
	 */
	public void update(BookCate bookCate){
		//实体是否存在
		Assert.notNull(bookCate,"商品分类实体不存在");
		Assert.notNull(bookCate.getCateId());
		Assert.hasText(bookCate.getName());
		bookCateDao.updateById(bookCate);
	}
	
	/**
	 * 根据id查询
	 * @return 
	 */
	public BookCate findById(int id){
		return bookCateDao.findById(id);
	}
	
	/**
	 * 根据id查询全部
	 * @return
	 */
	public List<BookCate> findAll() {
		return bookCateDao.findAll();
	}
}
